#ifndef _RADIAN_EDITOR_MATH_HELPER_H_
#define _RADIAN_EDITOR_MATH_HELPER_H_

#include "RadianCommon.h"
#include "OgreMath.h"
#include "math/vector3.h"
#include "OgreVector2.h"
#include "OgreQuaternion.h"

#include <QSize>
#include <QPoint>


/* Simple math helper.
*/
class RadianEditorMathHelper
{

public:
	/* Do a scene query,check which movale object has been itersected.
	*/
	static bool DoSceneQuery(Ogre::Camera* camera,Ogre::SceneManager* sceneMgr,const Ogre::Vector2& screenPos,const Ogre::String& movableType, Ogre::MovableObject*& outObj,Math::Vector3& outPos);

	/* Place on a mesh.
	*/
	static void PlaceOnMesh(Ogre::Camera* camera,Ogre::SceneManager* sceneMgr,const Ogre::Vector2& screenPos,Ogre::Entity* outEntity,Math::Vector3 outPos);


	/* Get mesh infomation.Ray cast the mesh in a polygon mode.
		-- from : http://www.ogre3d.org/tikiwiki/Raycasting+to+the+polygon+level
	*/
	static void GetMeshInformation(Ogre::MeshPtr mesh,size_t &vertex_count,Math::Vector3* &vertices,
								size_t &index_count, unsigned* &indices,
								const Math::Vector3& position = Math::Vector3::ZERO,
								const Ogre::Quaternion& orient = Ogre::Quaternion::IDENTITY,const Math::Vector3& scale = Math::Vector3::UNIT_SCALE);


	/* Obtaining the screenspace (2D) coordinates of a 3D MovableObject is a fairly common issue.
		The most common need for this ability is for determining 
		where to place an object's title (an overlay) on the screen.
	*/
	static bool GetScreenSpaceCoords(Ogre::MovableObject* object, Ogre::Camera* camera, Ogre::Vector2& result);


	/* Project world position to screen position.
	*/
	static Ogre::Vector2 WorldToScreen2D(const Math::Vector3& worldPos,Ogre::Camera* camera,size_t width,size_t height);


	/* Get the distance from a point to a line.
	*/
	static float DistanceToLine(float x1,float y1,float x2, float y2,float pX,float pY);

	/* Get the screen pos from the widget mouse position.
	*/
	static Ogre::Vector2 GetScreenPos(const QPointF& qtPos,const QSize& qtSize);

	/* Get merged aabb.
	*/
	static Math::AxisAlignedBox GetMergedAABB(const SceneNodeList& sceneNodes);

};
#endif